<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_FIELD_PATH."base_field_class.php");
    
	//
    // t_field_inspector
    //
	class t_field_inspector extends t_base_field
	{
        
        // property declaration
		// protected

        // property declaration
		// public
		// G
		const language_position_last = 1;
		// P
        const proper_properties_position_last = 1;
        // method declaration
    	// protected

		
        // G
		protected function get_field_event_script($a_event_type,$a_argouments)
        {			
			$local_return = '';
			return $local_return;
		}
static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = 'TRUE';
				break;                
			}*/
			return $local_return;
		}
		protected function get_proper_properties_position_last()      
		{
            return self::proper_properties_position_last;
        }
		
        // method declaration
    	// public
        public function __construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str)
		{
            parent::__construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str);
           
			
		}

		// C
		public function create_javascript_initialization_component()
		{
		
		}		
        public function create_tags_structure()
        {
            //echo __METHOD__."<BR>";
			global $g_javascript_namespace;
			global $g_cuteengine;
            parent::create_tags_structure();
            $local_name = $this->common_properties_array[t_base_field::common_properties_position_per_field_name];
            $local_current_tag = parent::add_tag(t_base_tag_type::btt_label,
                $local_name);
			$this->main_tag = $local_current_tag;
            $this->default_start_tag = $this->main_tag;
            $this->default_result_tag = $this->main_tag;
            
			// save button
			$local_tag = $this->main_tag;
			$local_tag = $local_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_input,$this->name.'_save_button');
			$local_tag->add_property('type','button');
			$local_tag->add_property('value','save');
			
			$local_tag->add_style_property("position","absolute");
			$local_tag->add_style_property("top","10px");
			$local_tag->add_style_property("right","10px");
			// log field
			$local_tag = $this->main_tag;
			$local_tag = $local_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$this->name.'_log');
			
			$local_tag->add_style_property("backgroundColor","DarkGray");
			$local_tag->add_style_property("border","1px solid");
			$local_tag->add_style_property("bottom","10px");
			$local_tag->add_style_property("left","2px");
			$local_tag->add_style_property("position","absolute");
			$local_tag->add_style_property("right","2px");				
			
			// Focudes component
			$local_tag = $this->main_tag;
			$local_tag = $local_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$this->name.'_selected');
			
			$local_tag->add_style_property("backgroundColor","yellow");
			$local_tag->add_style_property("border","1px solid");
			$local_tag->add_style_property("top","10px");
			$local_tag->add_style_property("left","2px");
			$local_tag->add_style_property("position","absolute");
			$local_tag->add_style_property("width","150px");		

			// Selected component
			$local_tag = $this->main_tag;
			$local_tag = $local_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$this->name.'_edited');
			
			$local_tag->add_style_property("backgroundColor","yellow");
			$local_tag->add_style_property("border","1px solid");
			$local_tag->add_style_property("top","30px");
			$local_tag->add_style_property("left","2px");
			$local_tag->add_style_property("position","absolute");
			$local_tag->add_style_property("width","150px");                

			// tag_main_moving_class_name style
			//echo "$this->name: ".method_exists($this->header_script_generator,add_style_sheet_property)." <BR>";
			$local_header_script_generator = $this->main_tag->header_script_generator;
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$tag_main_moving_class_name",'position','fixed');
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$tag_main_moving_class_name",'background-color','lightgrey');
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$tag_main_moving_class_name",'border','1px solid darkGray');
			//  STYLE
			// COMPONENT SELECTED
			$local_parent_tag = $this->main_tag;
			$local_html_tag_name = $this->name . "selected_component";
			$local_html_tag_class_name = $local_html_tag_name."_class_name";
			$local_tag = $local_parent_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_p,$local_html_tag_name);
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$local_html_tag_name","top","2px");
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$local_html_tag_name","left","5px");				
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$local_html_tag_name","position","absolute");
			// TAG SELECTED
			$local_parent_tag = $this->main_tag;
			$local_html_tag_name = $this->name . "selected_tag";
			$local_html_tag_class_name = $local_html_tag_name."_class_name";
			$local_tag = $local_parent_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_p,$local_html_tag_name);
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$local_html_tag_name","top","2px");
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$local_html_tag_name","left","20px");				
			/*$g_javascript_namespace*/$local_header_script_generator->add_style_sheet_property(".$local_html_tag_name","position","absolute");
			
			// POSITION AND DIMENSION
			$local_parent_tag = $this->main_tag;
			$local_html_tag_name = $this->name . "_pos_and_dim";
			$local_html_tag_class_name = $local_html_tag_name."_class_name";
			$local_table_tag = $local_parent_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_table,$local_html_tag_name);
			$local_table_tag->class_name = $local_html_tag_class_name;
			$local_table_tag->add_style_property("top","10px");
			$local_table_tag->add_style_property("left","5px");				
			$local_table_tag->add_style_property("bottom","5px");
			$local_table_tag->add_style_property("rigth","5px");	
			
			// moving_and_sizing_tags
			$this->main_tag->set_moving_and_sizing_tags(true);
			// JAVASCRIPT
			// property
			$g_javascript_namespace->header_script_generator->add_content_to_a_method(get_class($this),
				t_header_script_generator::create_label,"
			this.cuteengine.component_inspector = this;");
			
			// method
			// A
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"activate_editing_tag","","
			local_editing_tags = this.current_editing_tags_selection;
			if ((this.current_editing_tags != local_editing_tags) && (local_editing_tags != undefined))
			{
				if (this.current_editing_tags != undefined) 
				{
					this.deactivate_editing_tag(this.current_editing_tags);
				}
				this.current_editing_tags_associated = this.current_editing_tags_selection_associated;
				this.current_editing_tags = local_editing_tags;
				this.html_tag('".$this->name."_edited').innerHTML = this.current_editing_tags_associated.id;
				//
				this.current_editing_tags_selection = undefined;
				this.current_editing_tags_selection_associated = undefined;
				this.html_tag('".$this->name."_selected').innerHTML = '';
				if (local_editing_tags != undefined)
				{
					this.set_as_editor(local_editing_tags);
					local_editing_tags.on_resize_function = this.size_associated_tag.set_scope(this,local_editing_tags,this.current_editing_tags_associated);
				}    
			}");
			//echo "1 - " . get_class($this) . "<br> ";
			//$g_javascript_namespace->header_script_generator->add_property_to_a_class(
				//get_class($this), "activate_editing_tag","activate_editing_tag");    
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"activate_selection_tag","a_current_associated_tag,a_current_editing_tags_id","
			local_editing_tags = document.getElementById(a_current_editing_tags_id);
			if ((this.current_editing_tags_selection != local_editing_tags) && (local_editing_tags != undefined))
			{
				if (this.current_editing_tags_selection != undefined) 
				{
					this.deactivate_selection_tag(this.current_editing_tags_selection);
				}
				this.current_editing_tags_selection_associated = a_current_associated_tag;
				this.html_tag('".$this->name."_selected').innerHTML = this.current_editing_tags_selection_associated.id;
				this.current_editing_tags_selection = local_editing_tags;
				if (local_editing_tags != undefined)
				{
					set_size(a_current_associated_tag,local_editing_tags);
					this.set_as_selection(local_editing_tags);
					
				}    
			}");
		//	$g_javascript_namespace->header_script_generator->add_property_to_a_class(
			//	get_class($this), "activate_selection_tag","activate_selection_tag");    
			// D
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"deactivate_editing_tag","a_current_editing_tags","
			if (a_current_editing_tags != undefined)
			{
				a_current_editing_tags.style.visibility = 'hidden';
				if (a_current_editing_tags == this.current_editing_tags)
				{
					this.current_editing_tags = undefined;
					this.current_editing_tags_associated = undefined;
					this.html_tag('".$this->name."_edited').innerHTML = '';
				}
			}");
			//$g_javascript_namespace->header_script_generator->add_property_to_a_class(
				//get_class($this), "deactivate_editing_tag","deactivate_editing_tag");    
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"deactivate_selection_tag","a_current_editing_tags","
			if (a_current_editing_tags != undefined)
			{
				a_current_editing_tags.style.visibility = 'hidden';
				if (a_current_editing_tags == this.current_editing_tags_selection)
				{
					this.current_editing_tags_selection = undefined;
					this.current_editing_tags_selection_associated = undefined;
					this.html_tag('".$this->name."_selected').innerHTML = '';
				}
			}");		
			//$g_javascript_namespace->header_script_generator->add_property_to_a_class(
			//	get_class($this), "deactivate_selection_tag","deactivate_selection_tag");
			// G
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"get_component_property","","
			this.selected_component = document.getElementById(this.current_editing_tags_associated.id+'selected_component');
			if (this.current_editing_tags_associated != undefined)
			{	
				a_current_editing_tags.style.visibility = 'hidden';
				if (a_current_editing_tags == this.current_editing_tags)
				{
					this.current_editing_tags = undefined;
					this.current_editing_tags_associated = undefined;
				}
			};");		
			// S
			$local_parameters_list = new t_url_parameters_list(false);
			$local_parameters_list->add_new_parameter(
				$this->id,'save_component_style_to_database',
				"@'+local_component.name+'@'+local_sender_style+'@",
				t_url_parameter::request_type_no_page);
			//echo "local_parameters_list->compute_disguised_parameters_string():". $local_parameters_list->compute_disguised_parameters_string();	
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"save_page","a_sender","
		for(var i = 0; i<this.changed_components.length; i++)
		{
			var local_sender_style = '';
			var local_component = ".t_cuteengine::javascript_instance_name."[this.changed_components[i].name];  
			for(var e = 0; e<local_component.changed_tags.length; e++)
			{    
				var local_tag = this.html_tag(local_component.changed_tags[e]);
				local_sender_style += '::' + local_tag.id + '{';
				local_changed_style = local_tag.ce_extension.changed_style;
				for (var x in local_changed_style)
				{
					local_sender_style += x+':'+local_changed_style[x]+';';
				}
				local_sender_style += '}';
			}    
			". $this->parent_component->content_loader->add_execute_javascript_code('this.content_loader',
				$local_parameters_list,'false',
				'undefined','undefined')."                
		};");
			$g_javascript_namespace->header_script_generator->add_content_to_a_method(get_class($this),
				t_header_script_generator::create_label,"
			this.html_tag('".$this->name."_save_button').onclick = this.save_page.set_scope(this);
			");
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
				get_class($this),"size_associated_tag","a_sender,a_tag","
					set_size(a_sender,this.html_tag(a_tag.id));
		local_component = ".t_cuteengine::javascript_instance_name."[a_tag.id];
		if (set_changed_tag(a_tag.id) == true)
		{
			this.changed_components.push(local_component) 
		}");
			
			
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
				get_class($this), "set_as_editor","set_as_editor");
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
				get_class($this), "set_as_selection","set_as_selection");    
			
			// property
			// C
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
				get_class($this),"changed_components","[]");
				
			//$local_html_tag-> parent_div.onload
            
        }
        // G
		public function get_language_position_last()
        {
            return self::language_position_last;
        }
		public function get_result_action_script($a_event_type,$parent_event_type,
            $a_parameter,$a_content_loader_result)
		{
            return '';
        }		
		
// I
		public function initialize_field_event($a_event_type)
        {			
			
		}
        
       

		

    }
?>    